﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.OracleClient;
using System.Data;
using System.Configuration;
using APESM_GGJ.CommonClass;

/// <summary>
/// DBHelper 的摘要说明
/// </summary>
public class DBHelper
{

    public OracleConnection con = null;
    public  DataSet dset;
    public DBHelper()
    {
        if (con == null)
        {
            con = new OracleConnection(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
        }
        con.Open();

    }
    /// <summary>
    /// 执行查询sql
    /// </summary>
    /// <param name="sqlstr"></param>
    /// <returns></returns>
    public DataSet RunSql_Select(String sqlstr)
    {
        try
        {
            OracleCommand cmd = new OracleCommand(sqlstr, con);
            OracleDataAdapter oda = new OracleDataAdapter();
            oda.SelectCommand = cmd;
            dset = new DataSet();           
            oda.Fill(dset);            
        }
        catch (Exception ex)
        {
            LogHelper.WriteLog(typeof(DBHelper), ex);
        }
        finally {            
            //con.Close();
        }      
        return dset;
    }
    /// <summary>
    /// 执行插入sql
    /// </summary>
    /// <param name="sqlstr"></param>
    /// <returns>影响行数</returns>
    public int RunSql_Insert(String sqlstr)
    {
        int ret = 0;
        try
        {            
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = con;
            cmd.CommandText = sqlstr;
            ret = cmd.ExecuteNonQuery();  
        }
        catch (Exception ex)
        {
            LogHelper.WriteLog(typeof(DBHelper), ex);
        }
        finally
        {
            //con.Close();
        }
        return ret;
    }
}